home *** CD-ROM | disk | FTP | other *** search
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <MacWindows.h>
- #if UNIVERSAL_INTERFACES_VERSION >= 0x0330
- #include <ControlDefinitions.h>
- #endif
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <Devices.h>
- #include <StandardFile.h>
- #include <Movies.h>
- #include <Sound.h>
- #include <QuickTimeComponents.h>
- #include <ImageCompression.h>
- #include <Resources.h>
- #include <FixMath.h>
-
- #include "SortFrames.h"
- #include "Promiscuity.h"
-
- extern void createWindow(void);
- extern void idleWindow(void);
- extern void destroyWindow(void);
-
- Boolean gDone = false;
- Boolean gDrewJPEG = false;
-
- enum {
- kAppleMenuID = 128,
- kAppleMenuAbout = 1,
- kFileMenuID = 129,
- kFileMenuQuit = 1
-
- };
-
- static void doMenu( long menuSelection )
- {
- short whichMenu = HiWord(menuSelection);
- short whichMenuItem = LoWord(menuSelection);
-
- switch (whichMenu) {
- case kAppleMenuID:
- switch (whichMenuItem) {
- case kAppleMenuAbout:
- Alert(128, nil);
- break;
-
- default:
- {
- Str255 daName;
- GetMenuItemText(GetMenuHandle(kAppleMenuID), whichMenuItem, daName);
- OpenDeskAcc(daName);
- }
- break;
- }
- break;
-
- case kFileMenuID:
- switch (whichMenuItem) {
- case kFileMenuQuit:
- gDone = true;
- break;
- }
- break;
- }
- }
-
- int main( void )
- {
- GrafPtr wmgrPort;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- MaxApplZone();
-
- GetWMgrPort( &wmgrPort );
- SetPort( wmgrPort );
- EnterMovies();
-
- SetMenuBar(GetNewMBar(128));
- AppendResMenu(GetMenuHandle(kAppleMenuID), 'DRVR');
- DrawMenuBar();
-
- createStash();
- initPromiscuity();
- createWindow();
-
- while (gDone == false) {
- EventRecord theEvent;
- WindowPtr whichWindow;
- short windowPart;
- UInt32 timeoutTicks;
-
- idleWindow();
-
- gDrewJPEG = false;
- timeoutTicks = TickCount() + 5;
- while( !gDrewJPEG && ( TickCount() < timeoutTicks ) ) {
- idlePromiscuity();
- }
-
- WaitNextEvent(everyEvent, &theEvent, 0, nil);
-
- switch (theEvent.what) {
- case updateEvt:
- whichWindow = (WindowPtr)theEvent.message;
- SetPort(whichWindow);
- BeginUpdate(whichWindow);
- //drawWindow(whichWindow);
- EndUpdate(whichWindow);
- break;
-
- case keyDown:
- if (theEvent.modifiers & cmdKey) {
- doMenu(MenuKey(theEvent.message & charCodeMask));
- }
- break;
-
- case mouseDown:
- windowPart = FindWindow(theEvent.where, &whichWindow);
-
- switch (windowPart) {
- case inDrag:
- DragWindow(whichWindow, theEvent.where, &qd.screenBits.bounds);
- break;
-
- case inGoAway:
- if (TrackGoAway(whichWindow, theEvent.where))
- gDone = true;
- break;
-
- case inContent:
- if (whichWindow != FrontWindow())
- {
- SelectWindow(whichWindow);
- }
- else
- {
- //clickWindow(whichWindow, theEvent.where);
- }
- break;
-
- case inMenuBar:
- doMenu(MenuSelect(theEvent.where));
- break;
- }
- break;
- }
- }
-
- destroyWindow();
- termPromiscuity();
- destroyStash();
-
- return 0;
- }
-
- WindowPtr window = nil;
- GraphicsImportComponent gripJ = 0;
- GraphicsImportComponent gripG = 0;
-
- void createWindow( void )
- {
- OSErr err;
- Rect windowBounds;
-
- windowBounds = qd.screenBits.bounds;
- InsetRect(&windowBounds, 30, 50);
-
- window = NewCWindow( nil, &windowBounds, "\pEtherPEG", true, documentProc,
- (WindowPtr)-1, true, 0);
-
- SetPort( window );
-
- err = OpenADefaultComponent( GraphicsImporterComponentType, kQTFileTypeJPEG, &gripJ );
- if( err ) DebugStr( "\p couldn't open jpeg grip." );
- err = OpenADefaultComponent( GraphicsImporterComponentType, kQTFileTypeGIF, &gripG );
- if( err ) DebugStr( "\p couldn't open gif grip." );
- }
-
- void DisplayJPEGAndDisposeHandle( Handle jpeg );
-
- void idleWindow()
- {
- //•• call pmb...
- #define TEST_GRIP 0
- #if TEST_GRIP
- Handle h;
- h = Get1Resource( 'JPEG', 128 );
- if( h ) {
- DetachResource( h );
- DisplayJPEGAndDisposeHandle( h );
- }
- #endif // TEST_GRIP
- }
-
- void destroyWindow()
- {
- if( gripJ )
- CloseComponent( gripJ );
- if( gripG )
- CloseComponent( gripG );
- }
-
- void DisplayJPEGAndDisposeHandle( Handle jpeg )
- {
- OSErr err;
- Rect naturalBounds;
- MatrixRecord matrix;
- SInt32 gapH, gapV;
- Fixed scaleH, scaleV;
- Rect boundsRect;
- GraphicsImportComponent grip;
-
- if( !jpeg ) return;
-
- if( 'G' == **jpeg )
- grip = gripG;
- else
- grip = gripJ;
-
- err = GraphicsImportSetDataHandle( grip, jpeg );
- if( err ) goto bail;
- err = GraphicsImportGetNaturalBounds( grip, &naturalBounds );
- if( err ) goto bail;
-
- gapH = window->portRect.right - naturalBounds.right;
- gapV = window->portRect.bottom - naturalBounds.bottom;
-
- if( gapH >= 0 ) {
- gapH = ((UInt16)Random()) % gapH;
- scaleH = fixed1;
- }
- else {
- gapH = 0;
- scaleH = FixDiv( window->portRect.right, naturalBounds.right );
- }
-
- if( gapV >= 0 ) {
- gapV = ((UInt16)Random()) % gapV;
- scaleV = fixed1;
- }
- else {
- gapV = 0;
- scaleV = FixDiv( window->portRect.bottom, naturalBounds.bottom );
- }
-
- // need to use smaller scale of the two, and then recalc the other gap.
- if( scaleH > scaleV ) {
- scaleH = scaleV;
- gapH = window->portRect.right - FixMul(scaleH, naturalBounds.right);
- gapH = ((UInt16)Random()) % gapH;
- } else if( scaleH < scaleV ) {
- scaleV = scaleH;
- gapV = window->portRect.bottom - FixMul(scaleV, naturalBounds.bottom);
- gapV = ((UInt16)Random()) % gapV;
- }
-
- SetIdentityMatrix( &matrix );
- ScaleMatrix( &matrix, scaleH, scaleV, 0, 0 );
- TranslateMatrix( &matrix, gapH<<16, gapV<<16 );
-
- err = GraphicsImportSetMatrix( grip, &matrix );
- if( err ) goto bail;
-
- err = GraphicsImportDraw( grip );
- if( err ) goto bail;
-
- err = GraphicsImportGetBoundsRect( grip, &boundsRect );
- if( err ) goto bail;
- InsetRect( &boundsRect, -1, -1 );
- SetPort( window );
- FrameRect( &boundsRect );
-
- bail:
- DisposeHandle( jpeg );
- gDrewJPEG = true;
- }
-
-
- enum {
- kBlobSize = 6
- };
- void showBlob( short n )
- {
- static Boolean first = true;
- static Rect r, rx;
- static RGBColor black = { 0,0,0 };
- static RGBColor white = { 0xffff,0xffff,0xffff };
- static RGBColor blue = { 0,0,0xffff };
- static RGBColor green = { 0,0x8000,0 };
- static RGBColor yellow = { 0xffff,0xffff,0 };
-
- SetPort( window );
- RGBForeColor( 0 == n ? &yellow :
- 1 == n ? &black :
- 2 == n ? &green :
- &blue );
-
- if( first || r.right > window->portRect.right ) {
- first = false;
- r.left = 1;
- r.bottom = window->portRect.bottom - 1;
- r.top = r.bottom - kBlobSize;
- r.right = r.left + kBlobSize;
- }
- PaintOval( &r );
- RGBForeColor( &black );
-
- r.left += kBlobSize + 1;
- r.right += kBlobSize + 1;
-
- rx = r;
- rx.right += 10 * (kBlobSize + 1);
- EraseRect( &rx );
- }
-
-